package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsSearchHistory;
import com.qf.service.SearchHistoryService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/admin/history")
public class HistoryController {

    @Autowired
    private SearchHistoryService searchHistoryService;


    //http://localhost:8080/admin/history/list?
    //page=1&limit=20&userId=1&keyword=asdf&sort=add_time&order=desc
    @RequiresPermissions("admin:history:list")
    @RequiresPermissionsDesc(menu = {"用户管理","搜索历史"},button = "查询")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       Integer userId,String keyword,String sort,String order){

        IPage<DtsSearchHistory> iPage = searchHistoryService.findListByQuery(page,limit,userId,keyword,sort,order);
        Map data=new HashMap();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }

}
